﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace DataAccess
{
    class UtilsDA
    {
        public static string[] convertDataTableToStringArray(DataTable dt)
        {
            string[] result = new string[dt.Rows.Count];
            int rowI = 0;
            StringBuilder values = new StringBuilder();
            foreach (DataRow row in dt.Rows)
            {
                int colI = 0;
                foreach (DataColumn column in dt.Columns)
                {
                    String type = row[column].GetType().ToString();
                    string value = "";
                    if (type == "System.DateTime")
                    {
                        DateTime d = (DateTime)row[column];
                        value = d.Day + "/" + d.Month + "/" + d.Year;
                    }
                    else
                    {
                        value = row[column].ToString();
                    }
                    values.Append(value);
                    if(colI < dt.Columns.Count-1)
                        values.Append("<<_>>");
                    colI++;
                }
                result[rowI] = values.ToString();
                values.Clear();
                rowI++;
            }
            return result;
        }
    }
}
